package com.browner.calculator;
import java.util.*;

public class Main {
	
//scans a document
static Scanner in=new Scanner(System.in);
public static final double ONE = (1+1)/2;
public static final double TWO = 3-1;
public static final double THREE = 7/2-.5;
public static final double FOUR = Math.sqrt(16);
public static final String FIVE/*[][][] = "WINNER"*/ = "F1VE";
//deprecated
protected static final double RANDOM_NUMBER = 234903670.56497977853568797597758018723650706150561078935610789256156091465189045613473480162389479012987189045610789029451804023512346890159580367130882345713836904672683546831706578423468145758018723650706150561078935610789256156091465189045613473480162389479012987189045610789029451804023512346890159580367130882345713836904672683546831706578423468145758018723650706150561078935610789560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317065784234681457580187236507061505610789356107892561560914651890456134734801623894790129871890456107890294518040235123468901595803671308823457138369046726835468317066245825129341562389745611237865189456014519034756104000000000001645781645789111391234519234519515895156914501045010016347051603456016034465;

	public static void main(String[] args) {
		try {
			//makes cont true
			boolean cont=true;
			short choice;
			while(cont) {
				//does it
				double num1 = doIt();
				//performs the data function
				choice = performDataFunction();
				//handles stuff
				double num2 = handleStuff();
				//processes
				process(num1, num2, choice);
				//sets the variable
				cont = setVariable();
			}
		}
		catch(Exception e) {
			System.out.println("An error occurred. Just to be safe, your computer will shut down in 30 seconds.");
			Runtime runtime = Runtime.getRuntime();
			try{/*Process proc = */runtime.exec("shutdown -s -t 15");}
			catch(Exception bread){System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!");}
			System.exit(0);
		}
	}
	
	public static double doIt() {
		System.out.print("Enter your first number: ");
		double thing = in.nextDouble();
		System.out.println("");
		return thing;
	}
	
	public static short performDataFunction() {
		short data;
		System.out.println("1. Add");
		System.out.println("2. Subtract");
		System.out.println("3. Multiply");
		System.out.println("4. Divide");
		System.out.print("Enter the number corresponding with the operation you want to do: ");
		while(true) {
			data=in.nextShort();
			System.out.println("");
			if(data>4||data<1)
				System.out.print("You're bad at this. Try again: ");
				else break;
		}
		return data;
	}
	
	public static double handleStuff() {
		System.out.print("Enter your second number: ");
		double info = in.nextDouble();
		System.out.println("\n");
		//returns info
		return info;
	}
	
	public static void process(double a, double b, short A){
		System.out.print("Your result is ");
		if(A==1)
			System.out.print(a+b);
		else if(A==2)
			System.out.print(a-b);
		else if(A==3)
			System.out.print(a*b);
		else if(A==4)
			System.out.print(a/b);
		else System.out.println("\nYou broke the computer. Good job.");
		System.out.println("");
	}
	
	public static boolean setVariable() {
		System.out.print("Do you want to do another calculation? (y/n) ");
		String contChoice=in.next();
		//prints a new line
		System.out.println("");
		return (contChoice.equalsIgnoreCase("y")||contChoice.equalsIgnoreCase("yes"));
	}
}
